Add FindValueOfExpression function to evaluate symbolic expressions using solution values#20
Merged
kwesiRutledge merged 2 commits intomainfrom Oct 7, 2025
Conversation
Co-authored-by: kwesiRutledge <9002730+kwesiRutledge@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Can you create a function
Add FindValueOfExpression function to evaluate symbolic expressions using solution values
Oct 4, 2025
solution.FindValueOfExpression(s solution.Solution, expr symbolic.Expression) (float64, error)
that addresses issue #17 using the functions that we have built for the solution.Solution interface?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #20 +/- ##
==========================================
+ Coverage 86.76% 87.41% +0.64%
==========================================
Files 27 35 +8
Lines 3687 4163 +476
==========================================
+ Hits 3199 3639 +440
- Misses 440 470 +30
- Partials 48 54 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds a new
FindValueOfExpressionfunction to thesolutionpackage that evaluates symbolic expressions using variable values from a solution object. This addresses the need to compute the value of arbitrary expressions after solving an optimization problem.Motivation
When working with optimization problems, users often need to evaluate expressions (e.g., objective functions, constraint expressions, or derived quantities) using the optimal variable values found by the solver. Previously, there was no convenient way to do this programmatically using the
Solutioninterface.Changes
New Function
Parameters:
s Solution: A solution object containing variable valuesexpr symbolic.Expression: A symbolic expression to evaluateReturns:
float64: The evaluated value of the expressionerror: An error if any variable in the expression is missing from the solutionImplementation
The function:
ExtractValueOfVariablehelperUsage Example
Testing
Added 5 comprehensive test cases covering:
All tests pass successfully.
Design Decisions
Solutioninterface methods, maintaining compatibility with any implementationExtractValueOfVariablehelper for consistency with existing codeOriginal prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.